package com.xy.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ShiroController {
    Logger logger = LoggerFactory.getLogger(ShiroController.class);

    @GetMapping("/supply/find")
    public String supplyFind(){
        return "成功访问";
    }
    @GetMapping("/supply/add")
    public String supplyAdd(){
        return "成功访问";
    }
    @GetMapping("/supply/del")
    public String supplyDel(){
        return "成功访问";
    }
    @GetMapping("/supply/update")
    public String supplyUpdate(){
        return "成功访问";
    }
    @GetMapping("/purchase/find")
    public String purchaseFind(){
        return "成功访问";
    }
    @GetMapping("/purchase/add")
    public String purchaseAdd(){
        return "成功访问";
    }
    @GetMapping("/purchase/del")
    public String purchaseDel(){
        return "成功访问";
    }
    @GetMapping("/purchase/update")
    public String purchaseUpdate(){
        return "成功访问";
    }
    @GetMapping("/consignment/find")
    public String consignmentFind(){
        return "成功访问";
    }
    @GetMapping("/consignment/add")
    public String consignmentAdd(){
        return "成功访问";
    }
    @GetMapping("/consignment/del")
    public String consignmentDel(){
        return "成功访问";
    }
    @GetMapping("/consignment/update")
    public String consignmentUpdate(){
        return "成功访问";
    } @GetMapping("/carrier/find")
    public String carrierFind(){
        return "成功访问";
    }
    @GetMapping("/carrier/add")
    public String carrierAdd(){
        return "成功访问";
    }
    @GetMapping("/carrier/del")
    public String carrierDel(){
        return "成功访问";
    }
    @GetMapping("/carrier/update")
    public String carrierUpdate(){
        return "成功访问";
    }
    @PostMapping("/login")
    public String login(String username ,String password){
        Subject subject = SecurityUtils.getSubject();
        logger.info(username+" ===  "+password);
        UsernamePasswordToken token = new UsernamePasswordToken(username,password);
        try{
            subject.login(token);
        }catch (UnknownAccountException e){
            return "账号错误";
        }catch (IncorrectCredentialsException e){
            return "密码错误";
        }

        return "登录成功";
    }

    @GetMapping("/login/err")
    public String loginerr(){
        return "未认证";
    }
    @GetMapping("/auth/err")
    public String authErr(){
        return "没有权限";
    }









}
